// Include Windows functions
#include <Windows.h>
#include "OpenGLRenderer.h"
#include "ColladaReader.h"
#include "Data.h"

OpenGLRenderer* openglContext; // Our OpenGL Context class

bool running = true; // Whether or not the application is currently running

void init(Data* d)
{
	openglContext->init(d);
}
void display()
{
	openglContext->display();
}
void reshape(int w, int h)
{
	openglContext->reshape(w, h);
}
void keyboard(unsigned char key, int x, int y)
{
	openglContext->keyboard(key, x, y);
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	int width = 500;
	int height = 500;
	unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA  | GLUT_DEPTH | GLUT_STENCIL;
	glutInitDisplayMode (displayMode);
	glutInitContextVersion (3, 3);
	glutInitContextProfile(GLUT_CORE_PROFILE);
#ifdef _DEBUG
	glutInitContextFlags(GLUT_DEBUG);
#endif
	glutInitWindowSize (width, height); 
	glutInitWindowPosition (300, 200);
	int window = glutCreateWindow (argv[0]);
	
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
	
	ColladaReader* reader = new ColladaReader();
	Data* d = reader->read();

	GLenum err = glewInit();
	glGetError(); // Clear GL Error 1028

	if (GLEW_OK != err) {
		fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
		return 1;
	}

	openglContext = new OpenGLRenderer();

	init(d);

	glutDisplayFunc(display); 
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutMainLoop();

	delete openglContext;

	return 0;
}